#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>

int main()
{
    int fd[2];
    pipe(fd);

    pid_t pid = fork();
    if(pid == 0)
    {
        close(fd[1]);
        char buf[100];
        read(fd[0], buf, sizeof(buf));
        printf("子进程读到：%s\n", buf);
    }
    else
    {
        close(fd[0]);
        char msg[] = "hello from parent";
        write(fd[1], msg, strlen(msg) + 1);
    }

    return 0;
}
